import { useNoticeStore } from '@/stores/notice.js'
import { postNoticeHttp } from '@/Utils/api/notice.js'
import { Query } from '@/Utils/Query.js'
import { ref, toRefs, nextTick } from 'vue'
import { ElMessage } from 'element-plus'
export const useNotice = () => {
  const { isShow, noticeScope } = toRefs(useNoticeStore())
  // const tableData = [
  //   {
  //     date: '2016-05-03',
  //     name: 'Tom',
  //     address: 'No. 189, Grove St, Los Angeles'
  //   },
  //   {
  //     date: '2016-05-02',
  //     name: 'Tom',
  //     address: 'No. 189, Grove St, Los Angeles'
  //   },
  //   {
  //     date: '2016-05-04',
  //     name: 'Tom',
  //     address: 'No. 189, Grove St, Los Angeles'
  //   },
  //   {
  //     date: '2016-05-01',
  //     name: 'Tom',
  //     address: 'No. 189, Grove St, Los Angeles'
  //   }
  // ]
  const notice = ref({
    title: '',
    content: '',
    unit: ''
  })
  const units = ref([])
  const user_id = localStorage.getItem('use_id')
  notice.value.id = user_id
  const handleSub = () => {
    isShow.value = false
    // 添加公告
    postNoticeHttp(notice.value)
    ElMessage({
      message: '发布成功',
      type: 'success',
      duration: 1500
    })
  }
  nextTick(() => {
    Query.queryByLayer({
      service: { name: 'guanggu', layerId: 4 },
      callback: (res) => {
        units.value = res.map((item) => item.values_.values_.名称)
      }
    })
  })
  return { isShow, noticeScope, notice, units, handleSub }
}
